﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace Test_2D
{
    public partial class DragForm : Form
    {
        public DragForm()
        {
            InitializeComponent(); //actform = GetActiveWindow();
            FormBorderStyle = FormBorderStyle.None;
            ShowInTaskbar = false;
            SetStyle(ControlStyles.Selectable, false);
            Enabled = false;
        }


        [DllImportAttribute("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        //发送消息//winuser.h 中有函数原型定义
        [DllImportAttribute("user32.dll")]
        public static extern bool ReleaseCapture(); //释放鼠标捕捉winuser.h
        [DllImportAttribute("user32.dll")] //winuser.h
        private static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow);





        //private bool isFristShow = true;//标识是否是首次加载
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public static extern IntPtr GetActiveWindow();//获得当前活动窗体
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public static extern IntPtr SetActiveWindow(IntPtr hwnd);//设置活动窗体

        private IntPtr actform = IntPtr.Zero;//保存自己得到焦点前拥有活动窗体的柄


        public int mouse_x, mouse_y;

        private void DragForm_MouseMove(object sender, MouseEventArgs e)
        {
            //this.Left = Cursor.Position.X - 10; // this.Left - mouse_x + e.X;
            //this.Top = Cursor.Position.Y - 10; //this.Top - mouse_y + e.Y;
        }

        private void DragForm_MouseUp(object sender, MouseEventArgs e)
        {
            //MessageBox.Show("!!!");
            //this.Capture = false;
            //this.Dispose();
        }
    }
}
